package com.ctcemti.mdm.project.sys.entity;

import cn.afterturn.easypoi.excel.annotation.Excel;
import cn.afterturn.easypoi.handler.inter.IExcelDataModel;
import cn.afterturn.easypoi.handler.inter.IExcelModel;
import com.ctcemti.mdm.project.sys.entity.formdata.BaseReq;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.Id;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.util.Date;
import java.util.List;

@Data
@ApiModel("角色")
@JsonIgnoreProperties(value={"handler"})//避免很为mybatis懒加载时json序列化时忽略bean中的一些属性序列化和反序列化时抛出的异常.
public class OrgRole extends BaseReq implements IExcelModel,IExcelDataModel,Comparable<OrgRole> {
    @Id
    private String id;

    @ApiModelProperty(value = "名称")
    @Excel(name = "名称")
    @NotNull(message = "名称不能为空" )
    private String name;

    @ApiModelProperty(value = "排序")
    @Excel(name = "排序")
    @Pattern(regexp = "[0-9]*" ,message = "排序必须数字")
    private Integer sort;

    @ApiModelProperty(value = "适用组织")
    @Excel(name = "组织类型")
    @NotNull(message = "组织类型不能为空" )
    private String orgType;

    @Transient
    private String orgTypeName;

    @ApiModelProperty(value = "描述")
    @Excel(name = "描述")
    private String description;

    @Transient
    private List<OrgPerson> personList;

    /**
     * 创建人
     */
    @ApiModelProperty(value = "创建人")
    private String creator;

    /**
     * 创建时间
     */
    @ApiModelProperty(value = "创建时间")
    private Date createDate;

    /**
     * 修改人
     */
    @ApiModelProperty(value = "修改人")
    private String modifiedBy;

    /**
     * 修改时间
     */
    @ApiModelProperty(value = "修改时间")
    private Date modifyDate;

    @Transient
    @Excel(name = "错误提示")
    @ApiModelProperty(hidden = true)//swagger忽略属性
    private String errorMsg;

    @Transient
    @ApiModelProperty(hidden = true)//swagger忽略属性
    private int rowNum;

    @Override
    public int compareTo(OrgRole orgRole) {           //重写Comparable接口的compareTo方法，
        return this.rowNum - orgRole.getRowNum();// 根据行号升序排列，降序修改相减顺序即可
    }

}